package com.ruoyi.archive.service.impl;

import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.archive.mapper.ArchiveShapeMapper;
import com.ruoyi.archive.domain.ArchiveShape;
import com.ruoyi.archive.service.IArchiveShapeService;

/**
 * 户型信息Service业务层处理
 * 
 * @author yepanpan
 * @date 2025-04-17
 */
@Service
public class ArchiveShapeServiceImpl implements IArchiveShapeService 
{
    private static final Logger log = LoggerFactory.getLogger(ArchiveShapeServiceImpl.class);

    @Autowired
    private ArchiveShapeMapper archiveShapeMapper;

    /**
     * 查询户型信息
     * 
     * @param id 户型信息主键
     * @return 户型信息
     */
    @Override
    public ArchiveShape selectArchiveShapeById(Long id)
    {
        return archiveShapeMapper.selectArchiveShapeById(id);
    }

    /**
     * 查询户型信息列表
     * 
     * @param archiveShape 户型信息
     * @return 户型信息
     */
    @Override
    public List<ArchiveShape> selectArchiveShapeList(ArchiveShape archiveShape)
    {
        return archiveShapeMapper.selectArchiveShapeList(archiveShape);
    }

    /**
     * 新增户型信息
     * 
     * @param archiveShape 户型信息
     * @return 结果
     */
    @Override
    public int insertArchiveShape(ArchiveShape archiveShape)
    {
        ArchiveShape old = archiveShapeMapper.selectArchiveShapeByCode(archiveShape.getCode());
        if(old != null){
            throw new ServiceException("户型信息已存在:"+old.getCode());
        }
        archiveShape.setCreateTime(DateUtils.getNowDate());
        return archiveShapeMapper.insertArchiveShape(archiveShape);
    }

    /**
     * 修改户型信息
     * 
     * @param archiveShape 户型信息
     * @return 结果
     */
    @Override
    public int updateArchiveShape(ArchiveShape archiveShape)
    {
        ArchiveShape old = archiveShapeMapper.selectArchiveShapeByCode(archiveShape.getCode());
        if(old != null && !old.getId().equals(archiveShape.getId())){
            throw new ServiceException("户型信息已存在:"+old.getCode());
        }
        archiveShape.setUpdateTime(DateUtils.getNowDate());
        return archiveShapeMapper.updateArchiveShape(archiveShape);
    }

    /**
     * 批量删除户型信息
     * 
     * @param ids 需要删除的户型信息主键
     * @return 结果
     */
    @Override
    public int deleteArchiveShapeByIds(Long[] ids)
    {
        return archiveShapeMapper.deleteArchiveShapeByIds(ids);
    }

    /**
     * 删除户型信息信息
     * 
     * @param id 户型信息主键
     * @return 结果
     */
    @Override
    public int deleteArchiveShapeById(Long id)
    {
        return archiveShapeMapper.deleteArchiveShapeById(id);
    }


}
